﻿#include <iostream>

typedef char TElemType;
typedef struct BiTNode {
    TElemType data;
    struct BiTNode *lchild, *rchild;
} BiTNode, *BiTree;


void InitTree(BiTree &BT) {
    BT = NULL;
}

void CreateTree(BiTree &BT) {
    TElemType e;
    std::cin >> e;
    if (e == '#') {
        e = NULL;
    } else {
        BT = (BiTNode *) malloc(sizeof(BiTNode));
        BT->data = e;
        CreateTree(BT->lchild);
        CreateTree(BT->rchild);
    }
}


int TreeDepth(BiTree BT) {
    int Lh, Rh;
    if (!BT) return 0;
    Lh = TreeDepth(BT->lchild);
    Rh = TreeDepth(BT->rchild);
    return Lh > Rh ? Lh + 1 : Rh + 1;
}

void Visit(BiTree BT) {
    std::cout << BT->data;
}


/*
 * 已创建了一棵二叉树，分别编写函数，统计全部结点个数和叶子结点个数。
 */
int num = 0;
int CalLeaves(BiTree BT) {
    //
    if (BT->lchild == NULL && BT->rchild == NULL)
        num++;
    CalLeaves(BT->lchild);
    CalLeaves(BT->rchild);
    return num;
}

int CalNode(BiTree BT) {
    int num = 0;
    if (!BT) return num;
    return CalNode(BT->lchild) + CalNode(BT->rchild) + 1;
}

int main() {
    BiTree BT;
    InitTree(BT);
    std::cout << "请按照先序序列输入树结点创建一棵二叉树（'#'表示空）：\n";
    CreateTree(BT);


    int Node_num = CalNode(BT);
    std::cout << "该二叉树结点个数为：" << Node_num << "\n";
    int Leave_num = CalLeaves(BT);
    std::cout << "该二叉树叶子结点个数为：" << Leave_num;

    return 0;
}